package cn.sciento.farm.devicemanager.fjhsxq.model.common;

import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.util.MultiValueMap;

/**
 * @author 
 * @Description RestTemplate工具类
 * @Date 2017/10/10
 */
public class RestTemplateUtils {

    /**
     * 构造请求参数
     *
     * @param params json数据
     * @return
     */
    public static HttpEntity<String> buildHttpEntity(String params) {
        HttpHeaders headers = new HttpHeaders();
        MediaType type = MediaType.parseMediaType(MediaType.APPLICATION_JSON_UTF8_VALUE);
        headers.setContentType(type);
        headers.add("Accept", MediaType.APPLICATION_JSON_VALUE);
        return new HttpEntity<String>(params, headers);
    }
    
    /**
     * 
     * @param map form数据（map格式）
     * @return
     */
    public static HttpEntity<MultiValueMap<String, String>> buildFormEntity(MultiValueMap<String, String> map) {
    	HttpHeaders headers = new HttpHeaders();
    	MediaType type = MediaType.APPLICATION_FORM_URLENCODED;
    	headers.setContentType(type);
    	return new HttpEntity<MultiValueMap<String, String>>(map,headers);
    }

}
